package com.briup.bookstore.common.model.vo;

import com.briup.bookstore.common.model.entity.Book;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author YuYan
 * @date 2023-12-27 20:45:22
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BookVO {
    /**
     * 主键ID
     */
    private Integer id;
    /**
     * 图书名称
     */
    private String name;
    /**
     * 封面图片
     */
    private String cover;
    /**
     * 图书描述
     */
    private String description;
    /**
     * 作者
     */
    private String author;
    /**
     * 出版社
     */
    private String publisher;
    /**
     * 价格
     */
    private Double price;
    /**
     * 库存数量
     */
    private String storeNum;
    /**
     * 状态（0-上架，1-下架）
     */
    private Integer status;
    /**
     * 所属分类
     */
    private String categoryName;

    public static BookVO toVO(Book book) {
        return BookVO.builder()
                .id(book.getId())
                .name(book.getName())
                .cover(book.getCover())
                .description(book.getDescription())
                .author(book.getAuthor())
                .publisher(book.getPublisher())
                .price(book.getPrice())
                .storeNum(book.getStoreNum())
                .status(book.getStatus())
                .categoryName(book.getCategory().getName())
                .build();
    }
}
